import { Sequelize } from 'sequelize'
import { databaseConfig } from '../config'


const sequelize = new Sequelize(
  databaseConfig.database, 
  databaseConfig.userName, 
  databaseConfig.password, {
    host: databaseConfig.host,
    port: databaseConfig.port,
    dialect: 'mysql',
    logging: false
  }
);

// 同步模型到数据库
async function syncDatabase() {
  try {
    await sequelize.sync();
    console.log('Database synced successfully');
  } catch (error) {
    console.error('Error syncing database:', error);
  }
}
export {
  sequelize,
  syncDatabase
}